//
//  LibraryController.h
//  Bibliotecha
//	Actually a Model (MVC) despite the name...
//  Created by Jaime Garnica on 4/18/09.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import <Cocoa/Cocoa.h>
#import <PDFKit/PDFKit.h>
#import <openssl/md5.h>


@interface LibraryController : NSObject {
	
	NSXMLDocument *libraryFile;
	NSXMLDocument *bigLibraryFile;
	NSString *bigLibraryPath;
	NSString *libraryPath;
	NSMutableArray *types;
	NSMutableArray *categories;
	NSMutableArray *subjects;
	NSMutableArray *books;
	
	NSString *currentBook;
	NSString *search;
	
	PDFOutline *theOutline;
}

#pragma mark Accessor Methods

-(void)setLibraryPath: (NSString *)path;
-(NSString *)libraryPath;

-(void)setBigLibraryPath: (NSString *)path;
-(NSString *)bigLibraryPath;

-(void)setCurrentBook: (NSString *)book;
-(NSString *)currentBook;

-(void)setCurrentInfo: (NSMutableDictionary *)info;
-(NSMutableDictionary *)currentInfo;

-(void)setSearch: (NSString *)aSearch;

-(void)setTypes: (NSMutableArray *)newTypes;
-(NSMutableArray *)types;

-(void)setCategories: (NSMutableArray *)newCategories;
-(NSMutableArray *)categories;

-(void)setSubjects: (NSMutableArray *)newSubjects;
-(NSMutableArray *)subjects;

-(void)setBooks: (NSMutableArray *)newBooks;
-(NSMutableArray *)books;

-(void)setTheOutline: (PDFOutline *)anOutline;
-(PDFOutline *)theOutline;


#pragma mark Library File Methods

-(void)createLibraryFile;	//intialize a new NSXMLDocument if one does not exists at libraryPath already
							//should probably only happen once in lifetime of application

-(BOOL)loadLibraryFile;		//loads the library file from libraryPath into libraryFile

-(void)saveLibraryFile;		//saves the library file to libraryPath


#pragma mark Book Filtering

-(void)updateTypes;	//return an array of strings which represents the list of document types

-(void)updateCategoriesOfType: (NSString *)type;		//return an array of strings containing the categories

-(void)updateSubjectsOfCategory: (NSString *)category 
						andType: (NSString *)type;	//retrurn subjects of type and category

-(void)updateBooksOfSubject: (NSString *)subject		//return array of file names in
				andCategory: (NSString *)category			//type:category:subject
					andType: (NSString *)type;

-(NSArray *)returnBook: (NSString *)name;		//return all data of a record for display or editing



-(NSMutableArray *)makeUnique: (NSArray *)stuff;


#pragma mark Book Modification

-(BOOL)insertNewBookWithName: (NSString *)name atPath: (NSString *)path;

-(BOOL)removeBook: (NSString *)name toTrash: (BOOL)trash;			//remove a record from the library, and
																	//optionally move it to the trash

-(BOOL)modifyBook: (NSString *)name withData: (NSArray *)data;	//update data in libraryFile

-(BOOL)storeCurrentDestination: (PDFView *)aDocument;

-(void)checkForEmptyPath: (NSString *)oldPath;

#pragma mark Library Synchronization

-(BOOL)loadBigLibraryFile;		//loads the library file to synchronize to (bigLibraryFile)

-(void)saveBigLibraryFile;		//saves the library file to bigLibraryPath

-(BOOL)synchronizeLibraries;	//moves any new books from the smaller library up to the larger


@end
